#!/bin/bash


# ===================
# 定时备份 pg 数据库
# cron 
# 0 1 * * * sh /u01/pg_bak.sh
# ===================

pgpassword=fjcd@2022
svpath=/u01/mydata/pgbak/
pgpath=/usr/pgsql-14/bin/
dbusr=postgres
prjdb=DataCenter
#pgms=public
backupdata=DataCenter$(date +%Y%m%d)

pg_dump -h 127.0.0.1 -U ${dbusr} ${prjdb} > ${svpath}${backupdata}.sql

cd ${svpath}
tar -zcf ${backupdata}.tar.gz  ${backupdata}.sql
cp ${backupdata}.tar.gz /u01/share/datacenter/
rm -rf ${backupdata}.sql
find ${svpath} -name  "DataCenter*.gz" -mtime +15 -exec rm -rf "{}" \;
find /u01/share/datacenter/ -name  "DataCenter*.gz" -mtime +30 -exec rm -rf "{}" \;
